package com.example.select3;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class PlantSelectAdapter extends BaseAdapter {

    Context context;
    List<Plant> plants;

    public PlantSelectAdapter(Context context, List<Plant> plants) {
        this.context = context;
        this.plants = plants;
    }

    public PlantSelectAdapter() {
    }

    @Override
    public int getCount() {
        return plants.size();
    }

    @Override
    public Object getItem(int position) {
        return plants.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.select_item, null);
            holder = new ViewHolder();
            holder.icon = convertView.findViewById(R.id.icon);
            holder.title = convertView.findViewById(R.id.title);
            holder.desc = convertView.findViewById(R.id.desc);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Plant plant = plants.get(position);
        holder.icon.setText(plant.getIcon());
        holder.title.setText(plant.getTitle());
        holder.desc.setText(plant.getDesc());
        return convertView;
    }

    public final class ViewHolder {
        TextView icon;
        TextView title;
        TextView desc;
    }
}
